Why is my HTML link not replacing the whole URL? - html

I have a search engine using PHP/MySQL. I use this code to display the results from MySQL:
echo "<table width='300px'>
<h4><a href='$url'><b>$title</b></a><br />
$desc<br>
<font color='red'>$url</font></table></h4>
";
}
?>
However, if I add a URL (for example www.google.com) and I click on the title, it links me to http://mysite.com/www.google.com, instead of http://www.google.com.
How can I solve this?

Your $url is "www.google.com", which is not a complete URL.
Consequently, your HTML looks like this (you should have posted the resulting HTML, really, as PHP has nothing to do with this):
<table width='300px'>
<h4><a href='www.google.com'><b>sometitle</b></a><br />
somedescription<br>
<font color='red'>www.google.com</font></table></h4>
www.google.com is not a full URL, and so your browser is treating it as a relative path, and thus prepending the current domain.
Your $url should be a full URL, like "http://www.google.com".

Prefix your URLs with http:// ie. http://www.google.com
You could do it this way:
<a href='http://$url'><b>$title</b></a><br />

Related

Email Image not Showing (Gmail)

I've composed an email in HTML that has an image in it.
The image "src" attribute has a URL pointing to a controller action endpoint on my server (ASP.Net) which returns a FileContentResult.
An example of the img tag looks like this:
<img src="https://www.mywebsite.com/controller/action?argument=value" width="600" height="300" alt="HeadingImage" title="HeadingImage">
The email displays as expected in Outlook.
If I take the source from Outlook and just view it in Chrome desktop, it still works fine.
If I visit the img URL in Chrome the image is downloaded.
However, if I view the email in Gmail the image does not display. Why might this be the case?
I get a single error in the console looking something like this:
ci6.googleusercontent.com/proxy/<SNIP>https://www.mywebsite.com/controller/action?argument=value GET https://ci6.googleusercontent.com/proxy/<SNIP> 404 ()
Hi you can use this it's work for me
Including the scheme in the src url (using "//" does not work - use full scheme EG: "https://")
Including width and height attributes
Including style="display:block" attribute
Including both alt and title attributes
Just add http:// in image src
<img src="http://www.mywebsite.com/controller/action?argument=value" width="600" height="300" alt="HeadingImage" title="HeadingImage">
First You need to add that image on your deployed project folder and then you need to specify the path of your Image :
<img src="http://www.mywebsite.com/Images/YourImage.png" />
Cheers !!

Wordpress changes URL?

I have an image which serves as an a href, the following a href doesn't work:
<div id="buttonNext">
<a href="1-5/redrum-10">
<img id="buttonNextImg" src="../../resources/img/buttonImg/next.png"/></a>
</div>
Me clicking on the link results in me being redirected to this website:
http://localhost/redrumwordpress/wordpress/redrum-10/
which also exists, but it doesn't link me to the correct website, the following code does work and links to the correct website:
<div id="buttonNextBottom">
<a href="1-5/redrum-5/">
<img id="buttonNextImgBottom" src="../../resources/img/buttonImg/next.png"/></a>
</div>
Which re-directs me to the correct page:
http://localhost/redrumwordpress/wordpress/1-5/redrum-4/
I've checked if I missed something like a / or ../ maybe it was in the wrong folder.
I've checked for the file not being there, but it is and it isn't corrupt.
Could anyone help me with why WordPress won't link to the correct website, when I use this website outside of wordpress it works just fine.
Can't you use:
<?php bloginfo('url'); ?>
Which will get your site address, then add the link path relative to this?

How can I create a link to page and load specific content in iframe on that page

On our website we have a page that pulls content from another location in to an iFrame. I would like to know how I can create a link to the parent page and have a specific page load in the iFrame.
So, I'd like to create a link to http://xxx.xxx.com/page and have the iFrame on that page load http://yyy.xxx.com/anotherpage
You should give your iframe element a name attribute and then target that name in your anchor tag.
Like so:
<iframe src="iframe.htm" name="iframe_a"></iframe>
My link
Fiddle
See the MDN documentation for more info.
Hope it helps!
you'd have to add an iframe to http://xxx.xxx.com/page like this:
<iframe src="http://xxx.yyy.com/anotherpage"></iframe>
I was thinking:
Forms like https://www.w3schools.com/tags/att_form_method.asp this should give something like "index.php?getresult=someinput" right?
so if you link to your page like:
xxx.xxx.com/index.php?showpage=myrequestedpage
and
xxx.xxx.com/index.php
index.php contains
<?php
//pseudo-code to:
//function getiframe(){
//$showpage = $_GET (this should get "myrequestedpage") .".php";
//if no ?showpage available then $showpage = "defaultpage.php"
//}
// return $showpage;
?>
<iframe src="http://xxx.yyy.com/<?php getiframe(); ?>"></iframe>
I was having this in mind while I started searching for easyer/better solutions to the question Original Poster had, but I think this ... should ... work right?
ps. sorry for gravedigging(just noticed after writing the pseudocode), but i have the same question and thisone popped up on top in google, so hoping this would bring my thoughtprocess to a finished product as well and maybe someone has better idea's years later.
edit:
tested this to be working indeed. xxx.xxx.com/index.php?pagina=specificpage
<?php
if (empty($_GET['pagina'])) {
$pagina = "home.php";
}else{
$pagina = $_GET['pagina'].".php";
}
?>
<iframe src="<?php echo $pagina; ?>" style="border:none;" title="websites" height="100%" width="100%" name="target_frame"></iframe>

How to use an HTML # anchor in a dynamic URL

I want to link to a section of a dynamic page using the # anchor. Something like this:
<a href=page.php?id=3#section-name>LINK</a>
It didn't work. What is the right way to do it?
I'm not using a direct link, but a redirect like header("Location:page.php?id=3#section-name") from another script.
I have a section named section-name in file page.php. I guess page.php has a problem figuring out the value of the id to process (3 or 3#section-name). I am redirected to page.php which has its content repeated vertically.
You've only presented half of your code so I can only give a sample of the proper way to do it:
<body>
<a name="top"> </a>
<a href="#top">
Go To Top Of Page
</a>
</body>
When using anchor tags, you can target an element by its ID. Browsers will look for the ID before it looks for the name attribute when the link refers to such.
<a href="#section-name>LINK</a> will go directly to <div id="section-name"> if it exists.
Here's an example
Read: HTML Anchors with 'name' or 'id'?
A typical anchor tag works as follows:
A href link tag is written like so:
Jump to a001
See the #a001 above? That is referencing an id in the HTML page, and it will jump to it if you click this link.
To provide an example of how this id that we would jump to might look on a page, look below.
<li id="a001">text here</li>
Reference

simple way to display data in a .txt file on a webpage?

Working on a project, one of the webpages will display a list of people (specifically, a list of people from a graduation class that haven't been located yet).
Instead of manually updating these lists in tables which is a boneheaded Web 1.0 way of doing it, I'd like to take the submitted list of names, convert them to a simple .txt list, and then display that list on the webpage.
So far, the easist way to do this is to use an iframe element... only thing is, I cannot (or don't know how to) apply any text styling to the contents of the iframe. I've published a sample of what I've been able to accomplish here: http://dongarber.com/test//helpus-iframetest.html
The default font is courier, and the client probably ain't gonna be too keen on it.
Is there a better way to do this, that's doesn't require ASP.NET or a database?
#list p {
font: arial;
font-size: 14px;
}
...
<p>Help us locate all of our classmates from the High School class of 1961. If you know where they live or their e-mail addresses contact the Reunion Committee.</p>
<p> </p>
<div id="list"><p><iframe src="missingmen.txt" width=200 height=400 frameborder=0 ></iframe></p></div>
</div>
Easy way:
Rename missingmen.txt to missingmen.html.
Add a single line to the top of missingmen.html:
<link href="txtstyle.css" rel="stylesheet" type="text/css" />
Create a file called txtstyle.css, and add to it a line like this:
html, body {font-family:Helvetica, Arial, sans-serif}
In more recent browsers code like below may be enough.
<object data="https://www.w3.org/TR/PNG/iso_8859-1.txt" width="300" height="200">
Not supported
</object>
I find that if I try things that others say do not work, it's how I learn the most.
<p> </p>
<p>README.txt</p>
<p> </p>
<div id="list">
<p><iframe src="README.txt" frameborder="0" height="400"
width="95%"></iframe></p>
</div>
This worked for me. I used the yellow background-color that I set in the stylesheet.
#list p {
font: arial;
font-size: 14px;
background-color: yellow ;
}
If you just want to throw the contents of the file onto the screen you can try using PHP.
<?php
$myfilename = "mytextfile.txt";
if(file_exists($myfilename)){
echo file_get_contents($myfilename);
}
?>
How are you converting the submitted names to "a simple .txt list"? During that step, can you instead convert them into a simple HTML list or table? Then you could wrap that in a standard header which includes any styling you want.
That's the code I use:
<?php
$path="C:/foopath/";
$file="foofile.txt";
//read file contents
$content="
<h2>$file</h2>
<code>
<pre>".htmlspecialchars(file_get_contents("$path/$file"))."</pre>
</code>";
//display
echo $content;
?>
Keep in mind that if the user can modify $path or $file (for example via $_GET or $_POST), he/she will be able to see all your source files (danger!)
You cannot style a text file, it must be HTML
Most easy and simple way to show file on your web page
Here is a screenshot. You can see here a pdf and txt file.
Sample Screenshot of TXT file rendered on HTML using iframe.
<iframe
src="full_file_path_here"
frameBorder="0"
class=""
scrolling="auto"
height="100%"
width="100%">
</iframe>
You can add it as script file.
save the txt file with js suffix
in the head section add
<script src="fileName.js"></script>