How to make html transferable between computers without losing hyperlink and images?

Asked

Viewed 51 times

-1

I started programming a short time using HTML and my biggest problem is to do a project and when I take to other computers I take a long time changing the image paths and hyperlinks.

How to make links not break when I take my project to another computer?

Example, on my company pc the link is something like:

D: Desktop Programmer users my-project images logo.png

On my pc is

C: Users Joao Desktop my-project images logo.png

  • If in each computer you take your project the paths are different, you will have to change the same paths. Your question is too vague without an example code to be analyzed.

  • 2

    You will learn this over time. Usually you use a programming language that generates the HTML that will be sent to browser, with this it will be possible to create functions in this language, where this function will be responsible for creating a dynamic link (for other pages, images, etc.) just knowing what is the resource you intend to link. Only with HTML is more difficult to do something, probably the best idea is to work with relative addresses instead of absolutes, this already gives a flexibility well but still does not solve all cases.

  • 1

    I think I understand what you mean. Try to put a relative path in your images, that is, the path occurs from the current page. For example: <img src="~/Content/images/logotipo.png" alt="Logo" /> in this case, from the site location, it will fetch that path to the image

  • The strange thing about this question is that the structure of directories and files (paths) of the site (HTML) does not change when you upload everything together to another computer. I don’t know why I have to change that.

2 answers

5

To avoid or minimize this type of problem you can use relative paths.

To reference from the "folder" to which the file was opened, start the bar-free path, example:

You have the following structure:

  • index.html
  • images (folder)
    • soon.png
  • otherworldly.html
  • people (folder)
    • html person.

Your tag img would be:

<img src="imagens/logo.png">

Your hyperlink would be: Another file

Already the image in the file pessoa.html would have to "go back" a folder to locate the files, example:

<img src="../imagens/logo.png">

You can find more details in this link: https://www.w3schools.com/html/html_filepaths.asp

0

The real problem is that you use absolute paths to map your resources in Html, I recommend using relative paths, so when switching machines the problem will not exist

In your case, if the HTML file is in the folder D:\Users\Programador\Desktop\meu-projeto\ page path can be only images\logo.png, the system will fetch from the current path the folder images and then the file logo.png, regardless of where the folder is meu-projeto

Browser other questions tagged

You are not signed in. Login or sign up in order to post.