How to load all href links in a separate window - javascript

I am loading an HTML content parsed from an email to a frame. If the email contains an href link, it tries to open the link in its frame but I'd like to make it open in a new tab.
Normally, I'd do this by setting the target to _blank in the href, but the href tags are being read straight from the EML files, so unless if there's a better way, it seems like the only way I can accomplish this is to parse the HTML tags that is being read, find all href links and add the target to it. If possible, I'd like to avoid this option because parsing html adds a lot of downside to performance in general.
If anyone knows an elegant way of achieving this, please let me know.

This is not very elegant or semantic, but as a quick and dirty solution you can print a base tag before the first link:
<base target="_blank">
See http://www.w3schools.com/tags/att_base_target.asp for more info.

If you're using jQuery...
$('#frame a').click(function(event) {
event.preventDefault();
window.open($(this).attr('href'), '_blank');
});

Related

how to access the external website iframe having a title [duplicate]

I wonder if it is possible to get the page title of an url within IFRAME. I tried to use jQuery $('#iframe').attr('title') but that doesn't work. Please help. Thanks.
I think this is what you're looking for:
$(document).ready(function()
{
alert($('#iframe').contents().find("title").text());
});
That will return the page title that is located in the <title> tag of the iframe document that has the id "iframe".
I misread your question.
$('title', frames[frameName].document).text();
If what you are looking for is a way to get the URL of the iframe after the user has clicked on a link within that iframe, this is not possible in any modern browser that blocks cross-domain attempts.
Even though the iframe is part of the DOM and you can easily find the new iframe URL using apps like Firebug, Firefox will throw a XSS error on any attempts by js to directly pull that info.
But for the record, as it's already been said, the location within the DOM of the actual URL of the iframe content is (with a little help from jquery) : $("#id_of_iframe).contentDocument.location.href
I'm not totally sure if the above points straight to it with the above syntax, but that's the gist of it. The part that is a no-no is trying to go inside that contentDocument part.

Hide links from html

Suppose I have several links like
Google
How to remove the link so that user can't use view source to see the link.
It is impossible to hide the link completely from your code. You could handle links via javascript (harder to find the link?).
<a href="#" id="secretLink>Google</a>
<script>
document.querySelector('#secretLink').addEventListener('click',function(){
location.href = YOURDESTINATION;
});
</script>
But i don't recommend to do that.
Is's strictly impossible : the best way to understand it is that your browser itself needs the link ref to be able to jump to the page. If your browser can read this info, this means that you can read it somewhere, as well.

UI-router and linking to anchor tags on other pages?

I am trying to do a simple cross reference hyperlink, as in "see 'checkboxes' under the 'ui controls' section", which in plain html might be <a href="uicontrols.html#checkboxes">
In my ui-router-based app, I am trying to use
checkboxes
to go to the state/page elements.uicontrols and then the anchor tag on that page.
It doesn't work, and some Googling turned up this: https://github.com/angular-ui/ui-router/pull/1867
Does anyone know a way to accomplish links like this?
You can try it may be solved your problem. you should use id in anchor tag of plain html page to create reference link.
In ui-router-based app
<a ui-sref="elements.uicontrols({'#':'checkboxes'})">checkboxes</a>
in plain html might be
<a id="checkboxes" href="uicontrols.html">check to another page link</a>
N.B: should have sufficient content bellow the plain anchor tag to show that anchor tag at the top.

Extract an external dynamic link using Javascript

I'm not sure if this will be possible, but is there any way to extract the dynamic link under this webpage: http://www.mobileonline.tv/channel.php?n=69111 the dynamic link is named "Link 1 (HLS): not compatible with all channels" thanks
I suppose, besides xss, the only easy way is by
going to that page,
right clicking on that link,
click on inspect element.
The anchor tag should be highlighted for you in the developer tool. You can find the url in the href attribute of the anchor tag.

Get title string from url within iframe using jQuery?

I wonder if it is possible to get the page title of an url within IFRAME. I tried to use jQuery $('#iframe').attr('title') but that doesn't work. Please help. Thanks.
I think this is what you're looking for:
$(document).ready(function()
{
alert($('#iframe').contents().find("title").text());
});
That will return the page title that is located in the <title> tag of the iframe document that has the id "iframe".
I misread your question.
$('title', frames[frameName].document).text();
If what you are looking for is a way to get the URL of the iframe after the user has clicked on a link within that iframe, this is not possible in any modern browser that blocks cross-domain attempts.
Even though the iframe is part of the DOM and you can easily find the new iframe URL using apps like Firebug, Firefox will throw a XSS error on any attempts by js to directly pull that info.
But for the record, as it's already been said, the location within the DOM of the actual URL of the iframe content is (with a little help from jquery) : $("#id_of_iframe).contentDocument.location.href
I'm not totally sure if the above points straight to it with the above syntax, but that's the gist of it. The part that is a no-no is trying to go inside that contentDocument part.

Categories

Resources