I was wondering if it is possible through htaccess or somehow else (but NOT JS) to make all external links (links that are not domain related) to open in a new tab (target="_blank").
Is this even possible?
Thank you!
Any link that you generate in your page (I'm assuming you are generating the page with PHP), just do
if (strpos($link, 'yourdomain.com') === false)
{
//append your target="_blank" to the link here
}
Then you're searching the link for your domain and if it is not on your domain, then making it open in a new tab.
See http://us1.php.net/strpos
there are only 3 ways to decide this :
target-attribute
JS
Browser-Settings or Plugins (depends on what browser you use, most tend to use JS)
If you don't want to use JS, then you are pretty much only left with target. You could insert it "automatically" by PHP/Ruby/Python/Java-Code (whatever you use to generate your HTML), by using search and replace functions.
If you write your HTML yourself then you can set it for each link by hand.
I see no reason why you would need more options, but if you do: you're fucked.
Browsers don't get to see .htaccess and your server only delivers HTML-Files. It has no control about how they are processed. The browser decides this on it's own (this is where you could suggest to all your users to install a plugin to do this).
CSS3 property is there.
a
{
target-name:new;
target-new:tab;
}
But unfortunately, it's not supported by any browser.
Related
I am working on a site and the builders have used a mix of php and html for links. For example:
<li>Variable Speed Drives</li>
<li>Corrosion Resistant Baseplates</li>
and
<li>MP Repair</li>
<li>MTA Repair</li>
The php is referenced in another file in this way:
<?php
$pdf_link = "../pdf/";
$external_pdf_link = "../../pdf/";
$video_link = "../video/";
$external_video_link = "../../video/";
?>
My concern is not knowing the function of the php, other than it being a placeholder, and given that the links work both ways, I don't want to break something because I am clueless to its purpose.
In doing my due diligence researching, I ran across this post, which is close, but still no cigar, Add php variable inside echo statement as href link address?. All of the research seems to be about how rather than why. This is the site, and they only used it for the "Downloads" links: http://magnatexpumps.com/
Thank you...
B
There is no right way. They are just different.
Let's forget the PHP for a while. If you have this link in a page:
<a href='about.html'/>About</a>
What will happen? The browser will change the URL of the document. If you are at the root of the site like: "www.example.com", will redirect to "www.example.com/about.html". If you are in a URL like "www.example.com/news/index.html" will redirect you to "www.example.com/new/about". That's why sometimes it is useful to have a variable before, to force a full path URL.
Another case of URL variable interpolation is when you have different systems running in the same url. In this case, you will have to append the system name in order to get to where you want. If you don't know where your application will run if it will run on the doc root, or in a subfolder, use a variable to indicate the base path.
We have a website whose home page is http://bigbird.comp.nus.edu.sg/pmwiki/farm/appl/index.php As you see, it is based on pmwiki.
We find CSS, JS and other resources are loaded over http. That is because links generated by pmwiki's php files are prepended with http://. We want to remove the prepended http://. Links will become like:
<script src="//example.com/script.js"></script>
Which pmwiki's php files should we modify?
Steve finds the right link. Just need to find all urls in /local/config.php and modify them as follows:
if ($_SERVER["HTTPS"] == 'on') {
$FarmPubDirUrl = 'https://www.example.com/~someuser/pmwiki/pub';
} else {
$FarmPubDirUrl = 'http://www.example.com/~someuser/pmwiki/pub';
}
No need to modify the http:// links in your webpages. I have not done further research. I guess the code means: if the page is requested via https, the related url become https links.
More detailed explanations are welcome.
According to PmWiki.PathVariables and WikiFarms, the $FarmPubDirUrl and the related $FarmD variables are the ways PmWiki refers to static content.
I've got a project where we're creating a dynamic html5 based video player with a bunch of Ajax controls and features. The intention is that this player will be used by other domains. Our old player used flash and could easily domain-lock, but now is there any method at all to do domain locking in HTML5?
Keep in mind that's its not just the video itself, we're also wanting to load html content for our ajax based controls. It seems like iframe is the obvious choice for this but then there's no way to do domain locking.
Any ideas?
You could use the function above, but its pretty obvious what it's doing, so anyone can just remove the domain lock.
There are services out there that will lock your page to a domain name, I know of two off the top of my head.
jscrambler.com - this is a paid tool, but it might be a bit of an overkill if all you want to do is lock your domain.
DomainLock JS - this is a free domain locking tool.
I came here looking for the same thing. But I think I have an answer worked out.
The best way I found sofar is to strip the location.href of its http:// and then check the first few characters for a whitelisted domain. So:
if(checkAllowedDomains())
{
initApplication();
}
else
{
// it's not the right domain, so redirect them!
top.location.href="http://www.snoep.at";
}
function checkAllowedDomains()
{
var allowed_domains=new Array();
allowed_domains.push("www.snoep.at");
allowed_domains.push("www.makinggames.nl");
allowed_domains.push("www.google.com");
// add whatever domain here!
var domain=top.location.href;
domain.replace('http://','');
var pass=false;
for(i=0;i<allowed_domains.length;i++)
{
var shortened_domain=domain.substr(2,allowed_domains[i].length);
if(shortened_domain.indexOf(allowed_domains[i])!=-1)
{
pass=true;
}
}
}
This bit of code checks several allowed_domains, you can easily extend the array.
That is the problem with the code, it's very readable. So, I'd advise you to put it through a js-minimizer to make it less obvious and include it in EVERY js on your page. InitApplication() is a function that starts your page or application.
Because you strip the location of http:// (which may or may not be there) and then checking only for the specific length (including the WWW!) of the allowed domain, you rule out subdomains, that might look like this: google.com.mydomain.com and throw the check of!
Hope this helps.
Try reading REFERER header, and if the site isn't blacklisted, don't display player.
Is there a way to determine whether the user is using a web page in side and iframe or is it normal browsing using PHP?
Using the javascript code that #deceze mentioned above (I pasted it in below),
if (parent.frames.length > 0) { ... }
If the above code noticed the page was displayed within iframe, then call 'IAmInIFRAME.php'(just example) via ajax call.
You can add some GET parameters to the request while using IFRAME.
<iframe src="http://www.example.com/iframe?iframe=1">
But while non-iframe request there wouldn't be this GET parameter.
You can check is this GET parameter presents and define it in the session.
So there would be different sessions for iframe and usual window.
The solution is to see if the parent's location and the current window's location is the same. If it is the same, then the page was loaded normally, if it is different then the page was loaded in an iframe.
var isInIFrame = (window.location != window.parent.location) ? true : false;
This came from this website. http://www.24hourapps.com/2009/01/check-if-page-is-loaded-in-iframe-using.html, and it came from the SO question here Check if site is inside iframe.
NOTE: In one test, I got a cross browser origin error but that would also only come if the two locations were different.
I have an external javascript file that uses the getScript() function to run another JS file.
I have those all on static.mydomain.com. (I'm new to setting up CDNs)
getScript() doesn't seem to allow cross-domain requests because my HTML is on domain.com. But then I tried using relative paths according to this post: Dynamic URLs in CSS/JS
It works for CSS but does not work for JS (specifically within the getScript() function). What's going on here? What are some ways to mitigate this problem when dealing with CDNs?
The getScript method actually makes an ajax call, hence the reason it's not working. Unless you need access to things like 'was the script successfully found' and the like, it's better to just write up a quick method like...
function addScript(source, domain) {
$("head").append("<script src='"+ (domain ? domain + source : source) +"'></script>");
}
That will just add scripts to the head of the page, and let you add an optional domain to point to in case you want to change it up.