How to Add Iframe Current Domain on Visiting? - javascript

Listen this is main site link >>> http://magazinerpros.blogspot.com/
Now i want that if someone click on the above link. then it should open to hold another link too. like you see in Example #2. that hold extra frame link { http://www.inframe.com/p/preview.html? } before the main link.
Example #2
http://www.iframe.com/p/preview.html?url=http://www.inframe.com
I tried to add script on my testing site, but it continuously loading when visit it.
Script that i added in the below site.
<script type="text/javascript">
window.location.replace("http://www.iframe.com/p/preview.html?url=http://redirectssite.blogspot.com/");
</script>
http://www.inframe.com.
So please give me only javascript or jequery script. To make this redirection possible. which you see in example #2. So what script should i add in the site. so that after visiting it holds that another frame link before it in addressbar.

Looks like you are creating a redirect loop.
Either check the URL, like:
<script type="text/javascript">
if (window.location !== "http://redirectssite.blogspot.com/") {
window.location.replace("http://www.iframe.com/p/preview.html?url=http://redirectssite.blogspot.com/");
}
</script>
From the below script, it would work work fine
<script type="text/javascript">
if ( !(window.location !== window.parent.location) ) {
window.location.replace("http://www.inframe.com/p/preview.html?url=http://redirectssite.blogspot.com/");
}
</script>

Related

How to automatically click log in button using JavaScript

I want to save some JavaScript code as a bookmark in chrome so it automatically opens my university login site and clicks on on the login button. I am completely inexperienced in JavaScript, so I have no clue how to do this. I snipped together the following code, which opens the correct website, but then does not click on anything. The first URL automatically puts me to the login site (third URL in the code) in case I have not logged in yet in this window.
(function() {
window.location.replace("https://lms.uzh.ch/auth/MyCoursesSite/0");
window.onload = function(){
if (current_url.startswith('https://lms.uzh.ch/auth/MyCoursesSite/0')) {
return;
}
if (current_url.startsWith('https://lms.uzh.ch/dmz/')) {
document.getElementById("wayf_submit_button").click();
}
};
})();
I'm sorry if this is too obvious a question and annoys any experts but as I said I am a complete beginner. I would of course add the "javascript:" at the beginning for chrome to understand the bookmark.
When you use window.location.replace, you change the address and you code can't work anymore.
I can suggest using some browser extension, your "click function" should work then.
I guess you could also try to make some simple html page with iframe, you call your "click function" at this page, but you target it to the iframe. After that you can change browser's location to the university's webpage as you should already be logged in.
<html>
<head>
</head>
<body>
<iframe src="your_university_address.com" id="some_id" onload="click_button()"></iframe>
<script>
function click_button()
{
my_iframe=document.getElementById('some_id');
my_iframe.contentDocument.getElementById('your_button_id').click();
}
</script>
</body>
</html>
Very simple but it should do that job.
(You can achieve similar result by using window.open() I guess)

iFrame Redirect Issue - Not Changing the page

<iframe src="http://runebet.com/" width="80%" height="65%" name="runeBetAPI"></iframe>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script>
function RegisterPage() {
window.frames["runeBetAPI"].location = "http://runebet.com/register/";
}
RegisterPage();
</script>
This doesn't seem to work/change the content..
The URL should start with http://www. to avoid a server redirection
you can access iframe contents from the same domain only read here.
You can use the following to change the source of the iframe.
function changeSource(src, frameID) {
var frame= $('#' + frameID);
if ( frame.length ) {
frame.attr('src',src);
return true;
}
return false;
}
But apparently what looks like looking into what your code is doing the url that you are redirecting to it actually opens a registration form inside modal window, which for some reason is not opening if you access it via an iframe, because if you put the url http://runebet.com/register/ directly in the iframe and load the page it will still be showing the landing page so it is redirecting but the modal is not popping up that leaves you with the last thing that you have to trigger the Register link click and that can only happen if you are in the same domain if not maybe someone else knows, i dont.
$(window.frames[0].frameElement.contentDocument).find('a[href="/register"]').trigger('click');

Open iframe page in its parent when a direct link is to one of the child pages

Hi I have multiple pages that reside in an iframe and I would like them to open in the parent page when say a search engine indexes them or people directly link to them.
Example:
-this page will be the parent page and have an iframe
-this will be first page.php
-then there will be second page.php, third page.php, fourth page.php, ect.
I would like it if someone linked to any of the pages that require the iframe to load the parent page with the iframe and load the url into that iframe. So if someone links to say third page it will load the parent page and load third page in the iframe.
I have tried the following scripts that I have found from posts across the web but they only load the parent page with the original src in the frame.
<SCRIPT LANGUAGE='javascript'>
try {
if (top == self) {
top.location.href = 'parent page.php';
}
} catch(er) { }
</SCRIPT>
And
<script type="text/javascript">
if (window == top) {
var url = 'window.location.replace("parent page.php?var1=' + window.location.href + '")';
eval(url);
}
</script>
I also tried:
<body onload="refreshFrame();">
Then I saw the post on Open iframe page in parent frame (javascript) here and it just brings up the page that was linked to and not the iframe.
The pages in the iframe are dymanically created as well so idk if that has anything to do with it or not.
But nothing seems to open the page inside of the iframe on my site it only loads the parent page with the original src first page in it. So idk if this is possible with either javascript or php.
Also idk if anyone knows how this practice effects seo there are not many words and no tags on the parent page so I was just curious about that too.
Thanks
Did you try use the base tag in you iframe pages? Something like:
<base target="_parent" />
UPDATE
OK, so in your scenario you need to know if the current page is loaded on brownser or via iframe. And if it's not on iframe, redirect to your another page where you calling the iframe.
First thing first, check if the current page is inside a iframe with js:
<script type="text/javascript">
if ( self === top ) {
//Its not an Iframe;
}
</script>
Now that we know if the page isn't load via iframe we can use a redirect inside that if statament:
window.top.location="http://www.yourdomain.com";
Now you need to make sure after redirect the page, the iframe src attribute will be the same url it was before. I'm assuming you can do that with a get parameter int the url? Let me know if find trouble in that part.
UPDATE2
Just add a get parameter in the url as i mentioned above. Something like this:
<script type="text/javascript">
if ( self === top ) {
//Its not an Iframe, needs redirect:
var url = window.location;
window.location="http://www.yourdomain.com/index.php?iframe="+url;
}
</script>
Now in your index.php ( or whatever is the page that contain the iframe):
<?php
$iframe_url = (isset($_GET['iframe']) && !empty($_GET['iframe'])) ? $_GET['iframe'] : "initial-url-content";
?>
<iframe src="<?=$iframe_url?>"></iframe>

How to change The browser URL addresse when click on picture like instagram

If we have some pictures shown on the page as thumbnails, and when the user click on the picture , the page show the full picture using any JavaScript or JQuery methods.
how we can change the browser url address to point to picture instead of the main page website while keeping the user on the current page.
for example:
if we visit any instagram account for example
http://instagram.com/fofo
and when we click on any photo the script will change the address url in the browser to
http://instagram.com/p/ReTycBy2Bj/
for example
how we can do something that?
Thanks for help
You can achieve that by manipulating the browser history using the history.pushState() method on supported browsers. See https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries for details.
Here is an example of a script that will solve my question
After review +lshearer answer and start searching about "pushState" and while im searching I found this url http://html5.gingerhost.com/seattle which helps me to understand how to change the URL of browser address bar without loading it's content.
<html>
<head>
<title>some title</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<script>
$( document ).ready(function() {
// Handler for .ready() called.
var original_url = window.location.pathname;
$("#show").click(function() {
href = "picurlhere.jpg";
// HISTORY.PUSHSTATE
history.pushState('sss', 'New URL: '+href, href);
});
$("#close").click(function() {
// HISTORY.PUSHSTATE
history.pushState('sss', 'New URL: '+original_url, original_url);
});
});
</script>
<body>
<button id="show">showpic</button>
<button id="close">closepic</button>
<pre></pre>
</body>
</html>
I tested it on FireFox 25+, Chrome 31+
And it works.
When I click on 'showpic' button the script will change the url to 'picurlhere.jpg' and when I click back to 'closepic' button it will return me the original page URL.
This will help us while showing images using JQuery or JavaScript methods so we can change the browser url because if the user copy the link and send it to any one it will point him to the picture url not to the site page. and that is exactly used on instgram.
but in real show you have to make this script more smarter.
Thanks for Help.
No need to use any script, just plain HTML. Wrap your image like this:
<img src="your-image.jpg" alt="">

force left (nav) frame when show some pages

I've an old website, navigation in an frame at left, pages at right.
I want when an page is url'd directly the nav (left frame) shows also.
Until now I was an js working, but I don't know from when it are not working,
now returns this message:
Forbidden
You don't have permission to access /master.html on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.10 (Unix) mod_ssl/2.2.10 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at www.cpis.es Port 80
The code I was using is
http://www.webmasterworld.com/forum21/1205.htm
Call this javascript code from the HEAD section of each child page. The code creates a variable from the URL of the page, and then passes that variable in the new location's URL. This means a "master" frameset can load this exact page in the content section:
<SCRIPT LANGUAGE="JavaScript">
passpage = document.URL
if (top.location == self.location)
top.location.href="master.html?" + passpage
</script>
Then create just one "master.html" page. It holds the JavaScript code to decipher whatever URL is passed after the "?" and it writes that page into the content frame:
<html>
<head>
<title>Master Frameset</title>
</head>
<script language="JavaScript" type="text/javascript">
origURL = parent.document.URL
contentURL = origURL.substring(origURL.indexOf('?')+1, origURL.length)
document.write('<frameset cols="20%,80%"><frame src="leftnav.html" name="nav"><frame src="' + contentURL + '" name="content"><\/frameset>')
</script>
</html>
Thanks, Guillermo.
Sorry for delay.
Looks like the problem is in this little peace of javascript:
passpage = document.URL
if (top.location == self.location)
top.location.href="master.html?" + passpage
It should be:
passpage = window.location.pathname;
if (top.location == self.location) {
top.location.href="master.html?" + passpage;
}
You have to change that code in each page which you have in the link list. I think that should fix the problem.
I just checked the website and it seems to be working now. My guess is that there was no file located at http://www.cpis.es/master.html on server.
If the problem still exists please provide steps so we can reproduce it and see what went wrong.
Thanks Maiku Mori,
in order to properly test the problem please do the next:
go to www.cpis.es
click the second option in the menu (CoPrint)
ok, you see the leftnav + the page
now go directly to the page
go to www.cpis.es/coprint.htm
error, you got the forbidden page.

Categories