Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the FF behavior. The iFrame should be recreated each time #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ <h1>Click one of these labels:</h1>

<div href="blahblah:randomstuff">Non-exist protocol
</div>
<div href="surpassviewer://viewer.surpass.com">Viewer protocol
</div>
<div href="mailto:[email protected]">Send email
</div>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
Expand Down
14 changes: 10 additions & 4 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
$(function () {
$("div[href]").click(function (event) {
window.protocolCheck($(this).attr("href"),
let link = $(this).attr("href")
console.log("Link = ", link)
window.protocolCheck(link,
function () {
alert("protocol not recognized");
});
event.preventDefault ? event.preventDefault() : event.returnValue = false;
console.log("unrecognized")
}, function success() {
console.log("success")
}, function unSupported() {
console.log("unSupported")
})
event.preventDefault ? event.preventDefault() : event.returnValue = false
});
});
24 changes: 22 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ function _createHiddenIframe(target, uri) {
return iframe;
}

function _removeHidenIframe(target) {
let iframe = document.querySelector("#hiddenIframe")
if(iframe) {
if(iframe.parentElement == target) {
target.removeChild(iframe)
}
}
}

function openUriWithHiddenFrame(uri, failCb, successCb) {

var timeout = setTimeout(function () {
Expand Down Expand Up @@ -82,10 +91,21 @@ function openUriUsingFirefox(uri, failCb, successCb) {

try {
iframe.contentWindow.location.href = uri;
successCb();

setTimeout(function () {
if(iframe.contentDocument == null) {
frame = null
_removeHidenIframe(document.body)
failCb()
} else {
frame = null
_removeHidenIframe(document.body)
successCb()
}
}, 200)
} catch (e) {
if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL") {
failCb();
// failCb();
}
}
}
Expand Down
Loading