Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
57f8d218
Commit
57f8d218
authored
Aug 07, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #599 from edx/db/fix-studio-login-next
Assign isExternal JS function to window object
parents
16b5b951
82ac5606
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
common/static/js/utility.js
+8
-8
No files found.
common/static/js/utility.js
View file @
57f8d218
// checks whether or not the url is external to the local site.
// generously provided by StackOverflow: http://stackoverflow.com/questions/6238351/fastest-way-to-detect-external-urls
function
isExternal
(
url
)
{
window
.
isExternal
=
function
(
url
)
{
// parse the url into protocol, host, path, query, and fragment. More information can be found here: http://tools.ietf.org/html/rfc3986#appendix-B
var
match
=
url
.
match
(
/^
([^
:
\/
?#
]
+:
)?(?:\/\/([^\/
?#
]
*
))?([^
?#
]
+
)?(\?[^
#
]
*
)?(
#.*
)?
/
);
// match[1] matches a protocol if one exists in the url
// if the protocol in the url does not match the protocol in the window's location, this url is considered external
if
(
typeof
match
[
1
]
===
"string"
&&
match
[
1
].
length
>
0
&&
match
[
1
].
toLowerCase
()
!==
location
.
protocol
)
if
(
typeof
match
[
1
]
===
"string"
&&
match
[
1
].
length
>
0
&&
match
[
1
].
toLowerCase
()
!==
location
.
protocol
)
return
true
;
// match[2] matches the host if one exists in the url
// if the host in the url does not match the host of the window location, this url is considered external
if
(
typeof
match
[
2
]
===
"string"
&&
match
[
2
].
length
>
0
&&
if
(
typeof
match
[
2
]
===
"string"
&&
match
[
2
].
length
>
0
&&
// this regex removes the port number if it patches the current location's protocol
match
[
2
].
replace
(
new
RegExp
(
":("
+
{
"http:"
:
80
,
"https:"
:
443
}[
location
.
protocol
]
+
")?$"
),
""
)
!==
location
.
host
)
match
[
2
].
replace
(
new
RegExp
(
":("
+
{
"http:"
:
80
,
"https:"
:
443
}[
location
.
protocol
]
+
")?$"
),
""
)
!==
location
.
host
)
return
true
;
return
false
;
}
}
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment