How can I navigate to a URL using JavaScript through IE, I have tried most of the functions for JavaScript, and they doesn't work for IE.
window.location.href = ''; //doesn't work for IE
window.location = ''; //doesn't work for IE
window.open(""); //does work for IE but it opens it in a new tab and I don't want this
Please I need help with that.
Thank You.
EDIT!!!
window.location.href = ''; //works well for IE, the problem was that I was using jQuery to build my HTML and solved by: jQuery.mobile.navigate("url.html#subPg");
try this
self.location=”top.htm”;
tested in IE6,IE7
All the methods below should work in actuality -
1,
window.location.href=”login.jsp?backurl=”+window.location.href;
2,
window.history.back(-1);
3,
window.navigate(”top.jsp”);
4,
self.location=”top.htm”;
5,
top.location=”error.jsp”;
Try this :
<script language="javascript">
window.navigate("");
</script>
Or this :
<script language="JavaScript">
self.location="";
</script>
-Mohamed Shimran
Related
I'm trying to disable an input with JavaScript or jQuery
//document.getElementById("monto").disabled=true;
$(document).ready(function(){
$("#monto").attr("disabled", "disabled");
});
The code works fine in chrome, Firefox, and some versions of IE, but doesn't work with IE 8,
also tried with Hide/show but doesn't work too.
I know the best solution is to upgrade, but my boss thinks our clients are too dumb to do that.
try this article from stackoverflow :)
var disableSelection = function(){
$("#elementId").prop("disabled", true);
};
var enableSelection = function(){
$("#elementId").prop("disabled", false);
};
I have a link that opens a popup window using window.open(). The problem is the scrollbars don't work in Chrome. They work in IE and Firefox, so I'm thinking it has something to do with Chromes new scroll bars. This is an example of the code I'm using:
html:
Click Me
jQuery:
$('a').click(function() {
window.open("http://google.com", "", "width=300,height=300,scrollbars=1");
});
I also set up a jsfiddle here http://jsfiddle.net/88GBR/
Any thoughts would be much appreciated.
from http://www.w3schools.com/jsref/met_win_open.asp
scrollbars=yes|no|1|0 Whether or not to display scroll bars. IE, Firefox & Opera only
try to set css-prop explicitly overflow: scroll;, otherwise no chance I guess
Works fine for me, Chrome Version 32.0.1700.76 m running on Windows Vista x32
Tried to post screenshot but I don't have required rep, tried to post this as a comment instead of an answer but hey... don't have that rep either :D
in this way should work, but i would try the window.open action in a 'div' and not in an 'anchor'
$("#divClick").click(function(){
window.open("https://www.google.com","some","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=900px,height=500px");
}
In my case..
call 3 function then working fine~!!
document.open --> document.writer --> document.close
e.g.
var option = 'menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,resizable=yes,height=600,width=800';
var win = window.open(null, null, option);
var div = domConstruct.create('div');
/// add content in div ...
win.document.open(); // must call...
win.document.write(div.innerHTML);
win.document.close(); // must cal...
it worked for me, i find my crome was not supporting scrollbars=1 so i changed it as scrollbars=yes
var docprint = window.open('', '', 'scrollbars=yes,resizeable=yes,width=900, height=850');
docprint.document.open();
docprint.document.write('<html><head><title>Print Page Setup<\/title>');
docprint.document.write('<\/head><body onLoad="self.print()"><center>');
docprint.document.write(data);
docprint.document.write('<\/center><\/body><\/html>');
docprint.document.close();
docprint.focus();
This is the only way I found to get all three browsers to submit the form without problems. Is there an obvious reason why this is so? A more elegant solution to this? I'm using jQuery 1.9. Chrome is the odd man out here, as the code in the else is sufficient to submit via IE and Firefox.
function submitFormByPost(actionName){
$("#eventAction").val(actionName);
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome){
document.getElementById('myForm').method='POST';
document.getElementById('myForm').submit();
}
else{
document.forms[0].method='POST';
document.forms[0].submit();
}
}
jQuery should already provide a cross-browser way to submit a form. Try:
var $form = $("#myForm");
$form.attr('method', 'post');
$form.submit();
The way that works in Chrome will work in the others also, so just use that:
function submitFormByPost(actionName){
$("#eventAction").val(actionName);
var frm = document.getElementById('myForm');
frm.method = 'POST';
frm.submit();
}
Or using jQuery all the way:
function submitFormByPost(actionName){
$("#eventAction").val(actionName);
$('#myForm').attr('method', 'POST').submit();
}
This is for some older Chrome versions compability. Normally document.forms[0] works as well on Chrome as on other browsers. Easiest way to check, open Chrome console and write console.log(document.forms[0]); - works fine.
I have a master page which is having Javascript code which looks like this:
<script type="text/javascript">
function ClientPrint(str)
{
alert('before');
PrintControl.RawPrint(str);
alert('after');
}
</script>
And the child form is calling this Javascript by the code
Page.ClientScript.RegisterStartupScript(Me.GetType, "jcr", "ClientPrint('" & StrFinalBill & "')", True)
This code is working absolutely fine in IE but not in anyother browser in Firefox error console I’m getting this error “printcontrol is not defined”.
Can anyone please help me?
IE supports refering to a node via its id. for firefox and other browsers use -
function ClientPrint(str)
{
alert('before');
var PrintControl = document.getElementById(controlId);
PrintControl.RawPrint(str);
alert('after');
}
I've written a code that has successfully created a bookmark for any of the following browsers - IE, Firefox and Opera.
<script language="JavaScript" type="text/javascript">
function bookmark()
{
var title = 'Google';
var url = 'http://google.com';
if (document.all)// Check if the browser is Internet Explorer
window.external.AddFavorite(url, title);
else if (window.sidebar) //If the given browser is Mozilla Firefox
window.sidebar.addPanel(title, url, "");
else if (window.opera && window.print) //If the given browser is Opera
{
var bookmark_element = document.createElement('a');
bookmark_element.setAttribute('href', url);
bookmark_element.setAttribute('title', title);
bookmark_element.setAttribute('rel', 'sidebar');
bookmark_element.click();
}
}
</script>
Now I want my bookmark to run a piece of JavaScript code instead of surfing to Google, when the user clicks on it.
This is called a bookmarklet. You could try replacing 'http://google.com' with "javascript:alert('Annoying message');". However, Firefox at least doesn't allow adding bookmarklets using this API. I suspect IE and Opera may be the same.
You can try putting the js code in an html and then bookmark that html.