Previously, I got a solution from here on how to open another link automatically on page load. I got this code to do that
window.setTimeout("autoClick()", 2000); // 2 seconds delay
function autoClick() {
var linkPage = document.getElementById('dynLink').href;
window.location.href = linkPage;
}
</script>
dynLink is used in the body as target="_blank" within link tag. But this is loading the desired page within the same tab. Not in a New Tab.
I want when this auto page load clicks the link with id=dynLink, the page opens in a new tab then to load in the same tab.
And I really means New TAB - NOT NEW WINDOW.
Looking forward to some working solution. Thanks!
Following are some of the solutions using plain HTML and JavaScript. You may use based on your requirement and share if you have any other solution.
Open Link Immediately on Page Load.
<body onload="window.open('https://www.google.com/');">
Open link in New Tab on page load.
<body onload="window.open('https://www.google.com/', '_blank');">
Refresh the same URL Using meta tags.
<meta http-equiv="refresh" content="5" />
Refresh a different URL after 5 seconds Using meta tags.
<meta http-equiv="refresh" content="5;URL='https://www.google.com/'" />
Open different URL in New Tab using meta tags.
<meta http-equiv="refresh" content="5;URL=javascript:window.open('https://www.google.com/', '_blank');" />
You can try this:
var newTab = window.open('http://google.at', '_blank');
newTab.location;
Here is the fiddle: http://jsfiddle.net/70kdacL4/310/
For your specific case:
HTML:
<a id="link" href="http://www.google.at" target="_blank">TestLink</a>
JavaScript:
$(document).ready(function(){
window.setTimeout(function(){
var link = document.getElementById("link").href;
var newTab = window.open(link, '_blank');
}, 5000);
});
Be careful if you use a popup blocker. A popup blocker can prevent the tab from beeing opened.
Here is the fiddle: http://jsfiddle.net/qm9ss6s4/4/
The problem I am having is preventing a link from launching a new page and loading its href value in an iframe. The client site is using healcode a service that provides widgets to schedule fitness classes etc.Check this page When you click the signup button after the widget loads it opens a new page. What the client wants is to open that link on the same page or in a popup window. I have tried everything I can think of. I have used jQuery,fancybox, etc.
HERE IS THE CODE IM USING
screenshot.
What I think the problem is, is that my inline scripts loads before the widget scripts finish renders the the schedule html.
I know it is possible because this site uses the same widget and their signup opens the link in a overlay frame on the same page.
Please shed some light on this.
UPDATE:
<html>
<head>
<title>Test</title>
</head>
<body>
<iframe id="openViewHere" width="500px" height="500px" src="" ></iframe>
<script type="text/javascript">
healcode_widget_id = "7696499e81";
healcode_widget_name = "schedules";
healcode_widget_type = "mb";
document.write(unescape("%3Cscript src='https://www.healcode.com/javascripts/hc_widget.js' type='text/javascript'%3E%3C/script%3E"));
// Healcode Schedule Widget for Iyengar Yoga Association of Greater New York : Brooklyn Daily Class Schedule
</script>
<noscript>Please enable Javascript in order to get HealCode functionality</noscript>
<script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(".signup_now").click(function(){
var url = $(this).attr("href");
$("#openViewHere").attr("href",url);
return false;
});
</script>
</body>
</html>
Just use this code :
$( document ).ready(function(){
$("body").on('click',".signup_now",function(e){
$(this).attr("target","_self")
})
})
be aware that windows.ready() might fire , while the widget script is still adding elements dynamicaly that is why the listeners dont work , you have to access the element through already loaded parent ( e.g "body" ).
I am trying to open a local html file from a running html file.In simple words, when I click on a button in my html page it should open another html page which is stored on my computer only. I have tried using href but it is not working.I am using onclick so when i click on the button it opens a new window but the html is not loaded on the page.I can only use html or Java Script.
Here is what I am doing
<html>
<head>
<script lang="Java-Script">
function func()
{
var m='';
document.write(m);
}
</script>
</head>
<body>
<input type="Submit" value="click" onclick="func()">
</body>
</html>
Forget about document.write. If you wanted to add a link element to a web page (not needed here), you could try using document.createElement and document.body.appendChild.
If you want to navigate to an URL through Javascript, you can assign to window.location.
Instead of a button, maybe you can make a normal link in the first place?
Use jquery lib. It is very easy.
here you go!
http://fiddle.jshell.net/m7zq9/
I am doing a simple project, let us take high secure website. I have 5 different JSP pages. If I started from first JSP page, it is redirecting to second JSP page and so on. In the meanwhile, it should not store those pages in my browser history.
How to clear those browsing history using JavaScript?
Can you try using document.location.replace() it is used to clear the last entry in the history and replace it with the address of a new url. replace() removes the URL of the current document from the document history, meaning that it is not possible to use the "back" button to navigate back to the original document.
<script type="text/javascript">
function Navigate(){
window.location.replace('your link');
return false;
}
</script>
HTML:
<button onclick="Navigate()">Replace document</button>
As MDN Window.history() describes :
For top-level pages you can see the list of pages in the session history, accessible via the History object, in the browser's dropdowns next to the back and forward buttons.
For security reasons the History object doesn't allow the non-privileged code to access the URLs of other pages in the session history, but it does allow it to navigate the session history.
There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL.
So there is no Javascript method to clear the session history, instead, if you want to block navigating back to a certain page, you can use the location.replace() method, and pass the page link as parameter, which will not push the page to the browser's session history list. For example, there are three pages:
a.html:
<!doctype html>
<html>
<head>
<title>a.html page</title>
<meta charset="utf-8">
</head>
<body>
<p>This is <code style="color:red">a.html</code> page ! Go to b.html page !</p>
</body>
</html>
b.html:
<!doctype html>
<html>
<head>
<title>b.html page</title>
<meta charset="utf-8">
</head>
<body>
<p>This is <code style="color:red">b.html</code> page ! Go to <a id="jumper" href="c.html">c.html</a> page !</p>
<script type="text/javascript">
var jumper = document.getElementById("jumper");
jumper.onclick = function(event) {
var e = event || window.event ;
if(e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = true ;
}
location.replace(this.href);
jumper = null;
}
</script>
</body>
c.html:
<!doctype html>
<html>
<head>
<title>c.html page</title>
<meta charset="utf-8">
</head>
<body>
<p>This is <code style="color:red">c.html</code> page</p>
</body>
</html>
With href link, we can navigate from a.html to b.html to c.html. In b.html, we use the location.replace(c.html) method to navigate from b.html to c.html. Finally, we go to c.html*, and if we click the back button in the browser, we will jump to **a.html.
So this is it! Hope it helps.
It's not possible to clear user history without plugins. And also it's not an issue at developer's perspective, it's the burden of the user to clear his history.
For information refer to How to clear browsers (IE, Firefox, Opera, Chrome) history using JavaScript or Java except from browser itself?
No,that would be a security issue.
However, it's possible to clear the history in JavaScript within a Google chrome extension. chrome.history.deleteAll().
Use
window.location.replace('pageName.html');
similar behavior as an HTTP redirect
Read How to redirect to another webpage in JavaScript/jQuery?
to disable back function of the back button:
window.addEventListener('popstate', function (event) {
history.pushState(null, document.title, location.href);
});
Ok. This is an ancient history, but may be my solution could be useful for you or another developers.
If I don't want an user press back key in a page (lets say page B called from an page A) and go back to last page (page A), I do next steps:
First, on page A, instead call next page using window.location.href or window.location.replace, I make a call using two commands: window.open and window.close example on page A:
<a href="#"
onclick="window.open('B.htm','B','height=768,width=1024,top=0,left=0,menubar=0,
toolbar=0,location=0,directories=0,scrollbars=1,status=0');
window.open('','_parent','');
window.close();">
Page B</a>;
All modifiers on window open are just to make up the resulting page. This will open a new window (popWindow) without posibilities of use the back key, and will close the caller page (Page A)
Second: On page B you can use the same proccess if you want this page do the same thing.
Well. This needs the user accept you can open popup windows, but in a controlled system, as if you are programming pages for your work or client, this is easily recommended for the users. Just accept the site as trusted.
You cannot clear the browser history. It belongs to the user, not the developer. Also have a look at the MDN documentation.
Update: The link you were posting all over does not actually clear your browser history. It just prevents using the back button.
How do I remove an iframe before a page loads?
On my website I have users fill out a surveymonkey survey in an iframe. Upon completion of the survey, surveymonkey redirects to a page in my website domain. This new page is still trapped within the iframe; I want the iframe removed before this new page is loaded. I tried the following code, but this removes both the iframe AND the content of this new page I want loaded, producing a blank screen:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$('iframe', parent.document).remove();
});
</script>
</head>
</html>
<?php
//the content for the page I want loaded
?>
Any suggestions?
Cleaning up unanswered questions
You want a framebuster
if(top != self) top.location.replace(location);